﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CommonHealth : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string conList = "";
       string txtList = "";
        string strConn = ConfigurationManager.ConnectionStrings["MedicareConnectionString"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(strConn))
        {
            string typestr = "";
            
            string strCmd = "select * from  HealthKnowledge ";
            using (SqlCommand cmd = new SqlCommand(strCmd, conn))
            {
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                   
                    if (dr["Health_Type"].ToString() != typestr)
                    {
                        if (typestr != "")
                        {
                            txtList += "</div>";
                            conList += "<hr/></div>"; 
                        }

                        txtList += "<div class='showKnowledge' ><br/><br/><br/><h1>" + dr["Health_Type"] + "</h1>";
                        conList += "<div class='showKnowledgeDetail' ><h1 >" + dr["Health_Type"] + "</h1>";   
                        typestr = dr["Health_Type"].ToString();
                    }
                 
                    
                    //文字空白時換行
                    string strOld = dr["Health_Cont"].ToString();
                    string strNew = strOld.Replace("\r\n", "<br />");

                    txtList += "<h2 style='color:#ffa699'>" + dr["Health_Title"] + "</h2>";

                    if (dr["Health_img"] != DBNull.Value)
                    {
                        conList += "<h2>" + dr["Health_Title"] + "</h2>" + "<div style='height:200px;width: 550px; display: none;word-break:break-all;border:3px dotted #740000'><div style='float:left' ><img style='height:100px;width:100px' src='Handlers/HealthPic.ashx?Health_ID=" + dr["Health_ID"] + "' /></div><div style='float:right;width:400px;text-align:left;'><label>" + strNew + "</label></div></div>";
                    }
                    else
                    {
                        conList += "<h2>" + dr["Health_Title"] + "</h2>" + "<div style='height:200px;width: 550px; display: none;word-break:break-all;border:3px dotted #740000;text-align:left'>" + strNew + "</div>";
                    }
                    
                }
                conn.Close();


            }
        }
               this.Literal1.Text=  txtList+"</div>";
               this.Literal2.Text = conList + "</div>";
    }
}